package model;

import java.util.ArrayList;
import java.util.List;

/**
 * ShareMemory class for the simulator.
 * @author DoubleS
 * @version 1.0
 */
public class ShareMemory
{
  /**
   * The list of semaphores.
   */
  private List<Semaphore> my_sem_list;
  
  /**
   * Count the number of memory slots have been used.
   */
  private int my_counter;
  
  /**
   * Construct an empty ShareMemory.
   */
  public ShareMemory()
  {
    my_sem_list = new ArrayList<Semaphore>();
    my_counter = 0;
  }
  
  /**
   * 
   * @return The counter.
   */
  public int getCounter()
  {
    return my_counter;
  }
  
  /**
   * Add semaphore to the memory.
   * @param the_sem The semaphore.
   */
  public void addSemaphore(final Semaphore the_sem)
  {
    my_sem_list.add(the_sem);
    my_counter++;
  }
  
  /**
   * 
   * @param the_id The ID.
   * @return The semaphore with the specific ID.
   */
  public Semaphore getSemaphore(final int the_id)
  {
    return my_sem_list.get(the_id);
  }
}
